#!/bin/bash

sudo apt install build-essential subversion cmake python3-dev libncurses5-dev libxml2-dev libedit-dev swig doxygen graphviz xz-utils

wget https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-7.1.0.tar.gz

tar zxvf llvmorg-7.1.0.tar.gz

cd llvm-project-llvmorg-7.1.0

mkdir build && cd build
cmake -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="clang;lld;clang-tools-extra;" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_BUILD_DOCS=OFF ../llvm

# 防止内存不足, 建一个临时swap
mkdir tempswap
dd if=/dev/zero of=./tempswap/swap bs=64M count=32
sudo mkswap tempswap/swap
sudo swapon tempswap/swap

make -j 4
sudo make install/strip

# 删除挂载点和临时swap
sudo swapoff tempswap/swap
rm -rf tempswap
